/**
 * 接口模块
 */

// 导入 axios 请求实例 request
import request from '@/request/request'

// 登录
export const loginAPI = ({ username, password }) => {
  return request({
    method: 'POST',
    url: '/login',
    data: {
      username,
      password
    }
  })
}

// 获取 分类
export const getCateAPI = ({ curpage = 1, pagesize = 5 }) => {
  return request({
    method: 'GET',
    url: '/cates',
    params: {
      curpage,
      pagesize
    }
  })
}

// 新增分类
export const addCateAPI = ({ name, alias, isDelete = 0 }) => {
  return request({
    method: 'POST',
    url: '/addcate',
    data: {
      name,
      alias,
      is_delete: isDelete
    }
  })
}

// 删除分类
export const deleteCateAPI = (id) => {
  return request({
    method: 'get',
    url: `/deletecate/${id}`,
    params: {
      id
    }
  })
}

// 新增标签
export const addTagAPI = ({ name, type }) => {
  return request({
    method: 'POST',
    url: '/addtag',
    data: {
      name,
      type
    }
  })
}

// 获取标签
export const getTagAPI = ({ curpage, pagesize }) => {
  return request({
    method: 'GET',
    url: '/taglist',
    params: {
      curpage,
      pagesize
    }
  })
}

// 修改标签
export const updateTagAPI = function(data) {
  return request({
    url: '/updatetag',
    method: 'POST',
    data
  })
}

// 删除标签
export const delTagAPI = ({ id, isDelete = 1 }) => {
  return request({
    method: 'POST',
    url: '/deletetag',
    data: {
      id,
      is_delete: isDelete
    }
  })
}

// 新增文章
export const addNewActicle = ({
  title,
  describes,
  content,
  cateName,
  tagName,
  coverimg,
  createTime
}) => {
  return request({
    method: 'POST',
    url: '/addarticle',
    data: {
      title,
      describes,
      content,
      cateName,
      tagName,
      cover_img: coverimg,
      create_time: createTime
    }
  })
}

// 获取文章列表
export const getActicleListAPI = (query) => {
  return request({
    method: 'GET',
    url: '/articlelist',
    params: query
  })
}

// 通过id获取文章详情信息
export const getArticleByIdAPI = (id) => {
  return request({
    method: 'GET',
    url: '/getArticleInfo',
    params: {
      id
    }
  })
}

// 修改文章信息
export const updateArticleAPI = ({
  title,
  describes,
  content,
  cateName,
  tagName,
  coverimg,
  createTime,
  id
}) => {
  return request({
    method: 'POST',
    url: '/updateArticle',
    data: {
      id,
      title,
      describes,
      content,
      cateName,
      tagName,
      cover_img: coverimg,
      create_time: createTime
    }
  })
}

// 删除文章
export const deleteArticleAPI = (id) => {
  return request({
    method: 'POST',
    url: '/deletearticle',
    data: {
      id
    }
  })
}

// 获取基础设置
export const getSiteAPI = () => {
  return request({
    method: 'GET',
    url: '/basis'
  })
}

// 修改基础设置
export const updateSiteAPI = ([
  blogNname,
  websiteSuffixes,
  footerImg,
  copyRight,
  icp
]) => {
  return request({
    method: 'POST',
    url: '/updatebasis',
    data: {
      blog_name: blogNname,
      website_suffixes: websiteSuffixes,
      footer_img: footerImg,
      copyright: copyRight,
      ICP: icp
    }
  })
}

// 获取资料卡信息
export const getDataCardAPI = () => {
  return request({
    method: 'GET',
    url: '/datacard'
  })
}

// 修改资料卡信息
export const updateDataCardAPI = (data) => {
  return request({
    method: 'POST',
    url: '/setdatacard',
    data
  })
}

// 删除资料卡信息
export const removeDataCard = (field) => {
  return request({
    method: 'POST',
    url: '/deletedatacard',
    data: {
      field
    }
  })
}

// 获取页脚徽标
export const getFooterLogoAPI = () => {
  return request({
    method: 'GET',
    url: '/getFooterLogo'
  })
}

// 添加页脚徽标
export const addFooterLogo = (data) => {
  return request({
    method: 'POST',
    url: 'addfooterlogo',
    data
  })
}

// 删除页脚徽标
export const removeFlgAPI = function(id) {
  return request({
    method: 'POST',
    url: '/removefooterlogo',
    data: {
      id
    }
  })
}

// 修改页脚徽标数据
export const updateFlgAPI = function(ftlInfo) {
  return request({
    method: 'POST',
    url: '/updatefooterlogo',
    data: {
      ftlInfo
    }
  })
}

// 发布动态
export const writeDynamicAPI = function(data) {
  return request({
    url: '/relase',
    method: 'POST',
    data
  })
}

// 获取动态列表
export const getDynamicAPI = function() {
  return request({
    url: '/obtain',
    method: 'GET'
  })
}

// 删除动态
export const deleteDynamicAPI = function(id) {
  return request({
    url: '/delete',
    method: 'POST',
    data: {
      id
    }
  })
}

// 已id为参数获取动态详情
export const getByIdAPI = function(id) {
  return request({
    url: '/getbyid',
    method: 'GET',
    params: {
      id
    }
  })
}

// 修改动态详情
export const updateDyAPI = function({
  id,
  content,
  start,
  createTime
}) {
  return request({
    url: '/update',
    method: 'POST',
    data: {
      id,
      content,
      start,
      createTime
    }
  })
}

// 修改动态可见性
export const updateVbAPI = function(id, visibility) {
  return request({
    url: '/updatevb',
    method: 'POST',
    data: {
      id,
      visibility
    }
  })
}

// 修改关于我
export const upAboutmeAPI = function(data) {
  return request({
    url: '/upaboutme',
    method: 'POST',
    data
  })
}

// 获取关于我信息
export const getAboutmeAPI = function() {
  return request({
    url: '/getaboutme',
    method: 'GET'
  })
}
